package cn.pku.sirx.snad.uias.analyzer;

import org.springframework.util.Assert;

import cn.pku.sirx.snad.uias.util.AnalyzerUtils;
import cn.pku.sirx.util.MathUtils;

/**
 * @author WangXiao
 */
public class UserInfluenceAnalyzer implements IAnalyzer {

	public UserInfluenceAnalyzer() {
		weightVector = MathUtils.standardizeVector(weightVector);
	}

	@Override
	public double analyze(String fromUserId, String toUserId) {
		Assert.notNull(fromUserId);
		Assert.notNull(toUserId);
		if (fromUserId.equals(toUserId)) {
			return .0;
		}
		/*
		 * calculate value vector
		 */
		double[] valueVector = {
				userSimilarityAnalyzer.analyze(fromUserId, toUserId),
				userRelationshipAnalyzer.analyze(fromUserId, toUserId),
				userInteractionshipAnalyzer.analyze(fromUserId, toUserId) };
		/*
		 * adjust result
		 */
		double value = AnalyzerUtils.analyzeByWeight(weightVector, valueVector);
		// return MathUtils.binaryLogisticRegression(value);
		return value;
	}

	private double[] weightVector = { 3, 2, 5 };

	private IAnalyzer userSimilarityAnalyzer;
	private IAnalyzer userRelationshipAnalyzer;
	private IAnalyzer userInteractionshipAnalyzer;

	public void setUserSimilarityAnalyzer(IAnalyzer userSimilarityAnalyzer) {
		this.userSimilarityAnalyzer = userSimilarityAnalyzer;
	}

	public void setUserRelationshipAnalyzer(IAnalyzer userRelationshipAnalyzer) {
		this.userRelationshipAnalyzer = userRelationshipAnalyzer;
	}

	public void setUserInteractionshipAnalyzer(
			IAnalyzer userInteractionshipAnalyzer) {
		this.userInteractionshipAnalyzer = userInteractionshipAnalyzer;
	}

}
